﻿using System;
using System.Text;
using System.Collections.Generic;

namespace LibMSNP.HTTP
{
    public sealed class HTTPRequestHeader : HTTPHeader
    {
        public HTTPRequestHeader(string method, string resource)
            : base(method, resource) { }

        #region HTTPPacketHeader Inherited Member

        public override string this[string index]
        {
            get
            {
                return _headers[index];
            }
            set
            {
                _headers[index] = value;
            }
        }

        public override string ToString()
        {
            string temp = this._firstEntry + " " + this._secondEntry + " " + this.VERSION + this.LINE_END;
            foreach (KeyValuePair<string, string> header in _headers)
            {
                if (header.Value != string.Empty) 
                    temp += header.Key + ": " + header.Value + this.LINE_END;
            }
            temp += this.LINE_END;
            return temp;
        }

        public override byte[] ToBytes()
        {
            return ASCIIEncoding.ASCII.GetBytes(this.ToString());
        }

        public string Resource
        {
            get { return this._secondEntry; }
            set { }
        }

        public string Method
        {
            get { return this._firstEntry; }
            set { }
        }

        public override MimeHeaders Headers
        {
            get { return this._headers; }
        }

        public override string CacheControl
        {
            get { return _headers["Cache-Control"]; }
        }

        public override string Connection
        {
            get { return _headers["Connection"]; }
        }

        public override string Date
        {
            get { return _headers["Date"]; }
        }

        public override string ContentLength
        {
            get { return _headers["Content-Length"]; }
        }

        public override string ContentType
        {
            get { return _headers["Content-Type"]; }
        }

        public override string Server
        {
            get { return _headers["Server"]; }
        }
        
        #endregion
    }
}